/*script that manages the menu Editor*/

function MenuEditor(){

	var itemCurrentlyEdited = 1;
	var arrayCurrentlyEdited = window["tile"];
	var imageArrayCurrentlyEdited = window["tileImg"];

	this.onRadioButtonElementChange = function(){
		
		function getSelectedItem() {
			for (i=0; i<document.forms[0].radioElement.length; i++) {
				if (document.forms[0].radioElement[i].checked) {
					return document.forms[0].radioElement[i].value;
				}
			}
		}
		
		arrayCurrentlyEdited = window[getSelectedItem()];
		imageArrayCurrentlyEdited = window[getSelectedItem() + "Img"];
		itemCurrentlyEdited = 1;
		document.imageEdited.src = imageArrayCurrentlyEdited[itemCurrentlyEdited].src;
	}

	this.onArrowElementMore = function(){
		if (itemCurrentlyEdited < (imageArrayCurrentlyEdited.length - 1)) {
			onArrowElementChange(1);
		}
		else {
			onArrowElementChange(-imageArrayCurrentlyEdited.length+2);
		}
	}

	this.onArrowElementLess = function(){
		if (itemCurrentlyEdited > 1) {
			onArrowElementChange(-1);
		}
		else {
			onArrowElementChange(imageArrayCurrentlyEdited.length-2);
		}
	}

	function onArrowElementChange(step){
		//display the new image of the element edited
		itemCurrentlyEdited += step;
		document.imageEdited.src = imageArrayCurrentlyEdited[itemCurrentlyEdited].src;
	}

	this.getSelectedItemNumber = function(){
		return itemCurrentlyEdited;
	}
	
	this.getSelectedArray = function(){
		return arrayCurrentlyEdited;
	}
	
	function flush(){
		//not working
		tile[xmouse][ymouse] = 0;
		tileOver[xmouse][ymouse] = 0;
		monster[xmouse][ymouse] = 0;
		building[xmouse][ymouse] = 0;
	}
}